﻿Imports Entidad
Imports Utilitario
Imports System.Data.SqlClient
Public Class TablaMasivaDatos
    Inherits ConexionSQL
    Dim cmd As SqlCommand
    Public Function ConsultarTablasMasivas(ByVal nivel As String) As DataTable
        Try
            conectarSQL()
            Dim da As New SqlDataAdapter("", cnn)
            Dim ds As New DataSet
            Dim actIng As String = ""
            If nivel.Equals("0") Then
                actIng = " and utm.UST_Actualiza='1'"
            End If
            If nivel.Equals("1") Then
                actIng = " and utm.UST_Ingresa='1'"
            End If
            da.SelectCommand.CommandText = "SELECT tm.TMA_Codigo, tm.TMA_Descripcion, tm.TMA_Ruta, tm.TMA_Activo, tm.TMA_Campos, tm.TMA_Valores " & _
                " FROM Tabla_Masiva tm " & _
                " INNER JOIN UsuarioTablaMasiva utm ON utm.CIA=tm.CIA and utm.TMA_Codigo=tm.TMA_Codigo and utm.UST_Activo='1' and utm.USU_Codigo='" & Variables.Usuario.gUSU_Codigo & "' " & IIf(actIng.Equals(""), "", actIng) & _
                " WHERE tm.TMA_Activo='1' and tm.CIA='" & Variables.Empresa.gCIA_Codigo & "'"
            da.Fill(ds, "Tabla_Masiva")
            Return ds.Tables("Tabla_Masiva")
        Catch ex As Exception
            MsgBox(ex.Message)
            Return Nothing
        Finally
            desconectarSQL()
        End Try

        Return Nothing
    End Function


End Class
